package cn.com.wangluotongxin.member.event;

import cn.com.wangluotongxin.member.rabbitmq.listener.MemberRabbitmqConstants;
import cn.com.wangluotongxin.member.rabbitmq.pojo.MemberInfoLoginPojo;
import cn.com.wangluotongxin.rabitmq.service.RabbitmqCommonPushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class MemberLoginPushEventHandler implements ApplicationListener<MemberLoginPushEvent> {

    @Autowired
    private RabbitmqCommonPushService commonPushService;

    @Async
    @Override
    public void onApplicationEvent(MemberLoginPushEvent event) {
        MemberInfoLoginPojo infoLoginPojo = new MemberInfoLoginPojo()
                .setId(event.getPojo().getId())
                .setUsername(event.getPojo().getUsername())
                .setOnlineStatus(event.getPojo().getOnlineStatus())
                .setPhone(event.getPojo().getPhone());
        commonPushService.push(MemberRabbitmqConstants.MEMBER_INFO_LOGIN_PUSH, infoLoginPojo);
    }
}
